/*-------------------------------------------------------------------------

***************** Modification History ***********************************
   @doc
   @module custoper.c - Operation functions |
   @end
   
$Log: /SoftPay/SPK2SIM/Source/Main/custoper.c $ 
 * 
 * 6     3/20/00 8:17p Vipin_k1
 * Added the custom Tip entry function
 * 
 * 5     3/20/00 3:37p Vipin_k1
 * Added custom functions for Total amount computation and display
 * 
 * 4     3/20/00 2:14p Vipin_k1
 * Added custom functions for the base amount entry
 * 
 * 3     3/18/00 11:26p Vipin_k1
 * Modifiedcust logo  function headers
 * 
 * 2     3/18/00 11:23p Vipin_k1
 * Added the custom operations functions for the init of display and the
 * custom logo display
 * 
 * 1     3/17/00 2:47p Vipin_k1
 * Custom UI opeartions for the SP2000 base

**************************************************************************

   Copyright (C) 1999 by VeriFone, Inc.

   All rights reserved.  No part of this software may be reproduced,
   transmitted, transcribed, stored in a retrieval system, or translated
   into any language or computer language, in any form or by any means,
   electronic, mechanical, magnetic, optical, chemical, manual or otherwise,
   without the prior written permission of VeriFone, Inc.

---------------------------------------------------------------------------*/
#ifdef IMAM_LOG
#ifndef LOGSYS_FLAG
#define LOGSYS_FLAG
#endif
#endif

#define VSOPER_C

#include <aclconio.h>
#include <stdio.h>
#include <stdlib.h>
#include <applidl.h>
#include <acldev.h>
#include <svctxo.h>
#include <dbmgr.h>
#include <project.h>
#include <string.h>
#include <aclstr.h>
#include <ctype.h>
//#include <beetle.h>


/** /#define DEBUG_VSOPER */
#ifdef DEBUG_VSOPER
#define DEBUG_95
#endif


#include <define.h>
#include <transact.h>
#include <oper.h>
#include <gds.h>
#include <fct.h>
#include <accum.h>
#include <date.h>
#include <menufunc.h>
#include <ui.h>
#include <msg.h>
#include <msgfuncs.h>
#include <hdt.h>
#include <opt.h>
#include <tct.h>
#include <table.h>
#include <tran.h>
#include <spdebug.h>
#include <pform.h>
#include <settle.h>
#include <operate.h>
#include <pbatch.h>
#include <entry.h>
#include <lct.h>
#include <cdt.h>
#include <confio.h>
#include <passwd.h>
#include <pcheck.h>
#include <opedit.h>
#include <report.h>
#include <mit.h>
//#include <codesec.h>
#include <logo.h>
#include <xmodem.h>
#include <modemmsg.h>

#include "custoper.h"
#include <sizes.h>
#include <multilng.h>
#include <spamsg.h>
#include <format.h>
#include <tip.h>

#include "cpacsize.h"
#include "cpac.h"
#include "cpacextn.h"

extern int inGetCPACMaxAmtEntryDigits(void);
extern int inImamLineNumber;
#if 0
/********************************************************************************************* 
* @func int | inCustDisplayAtInit | 
*
* Custom display start up operations
*      
* @parm  void|void |
*
* @rdesc VS_SUCCESS or error code.
* @end
**********************************************************************************************/


int inCustDisplayAtInit(void)
{
    char szMessage [MESSAGE_SIZE + 1];
    
        inDisplayCustLogo (1, 1, "F:SPTLOGO.VFT", 16, 1, CHARS_8X16, 8);      // Puts the top small logo
        vdDelay(PROMPT_DELAY);              
        inDisplayCustLogo (1, 1, "F:SPMAIN.VFT", 8, 4, CHARS_4X8, 0);      // Puts the BIG SP LOGO
        vdDelay(PROMPT_DELAY);
        inDisplayCustLogo (1, 1, "F:SPLLOGO.VFT", 8, 4, CHARS_4X8, 0);      // Puts the default softpay LOGO

        vdGetMessageFromFile( CUST_COPYRIGHT_MSG1, szMessage);  // Copy Right 2000
        inMLDisplayAt (1, 4, szMessage, CLR_EOL, ML_USE_GIVEN_FONT, ML_MENU_FONT, ASC4X16_VFT);
        vdDelay(PROMPT_DELAY);
                
        vdGetMessageFromFile( CUST_COPYRIGHT_MSG2, szMessage);  // Copy Right 2000
        inMLDisplayAt (1, 4, szMessage, CLR_EOL, ML_USE_GIVEN_FONT, ML_MENU_FONT, ASC4X16_VFT);
        vdDelay(PROMPT_DELAY);

        vdGetMessageFromFile( CUST_COPYRIGHT_MSG3, szMessage);  // Copy Right 2000
        if (strlen (szMessage))   // Display this message only if you have a string
        {
            inMLDisplayAt (1, 4, szMessage, CLR_EOL, ML_USE_GIVEN_FONT, ML_MENU_FONT, ASC4X16_VFT);
            vdDelay(PROMPT_DELAY);
            inMLDisplayAt (1, 4, " ", CLR_EOL, ML_USE_GIVEN_FONT, ML_MENU_FONT, ASC4X16_VFT);
        }
           return (VS_SUCCESS);
}

#endif /* 0 */

/********************************************************************************************* 
* @func int | inCustomDisplayLogo| 
*
* Display of the custom logo at start up
*      
* @parm void | void |
*
* @rdesc VS_SUCCESS or error code.
* @end
**********************************************************************************************/


int inCustomDisplayLogo(TRANSACTION_OBJECT* pobTran) {
    //char szLogoName [MESSAGE_SIZE + 1];
    char szFontName[FILENAME_SIZE + 1];
	int inImamYPos = 1;

    memset(szFontName, 0, sizeof(szFontName));

	if (inImamLineNumber == 16) inImamYPos = 3;
    if (inDisplayCustLogo(1, inImamYPos, "F:custlogo.vft", 8, 4, CHARS_4X8, 0) == VS_SUCCESS) // Has to be 16X16 font (VFT)
        vdDelay(PROMPT_DELAY); 

    get_font(szFontName);

    set_font(ASC4X16_VFT);
    vdDisplayAt(16, 1, " ", CLR_EOL);
    vdDisplayAt(16, 2, " ", CLR_EOL);
    vdDisplayAt(16, 3, " ", CLR_EOL);
    vdDisplayAt(16, 4, " ", CLR_EOL);
    vdDisplayAt(16, 5, " ", CLR_EOL);
    vdDisplayAt(16, 6, " ", CLR_EOL);
    vdDisplayAt(16, 7, " ", CLR_EOL);
    vdDisplayAt(16, 8, " ", CLR_EOL);

	clrscr();

    set_font(szFontName);

    return (VS_SUCCESS);
}

/*---------------------------------------------------------------------------
    Function     : inCustGetBaseAmount
    Description  : Gets the base amount for the transaction.
    Returns      : VS_ERR, VS_SUCCESS or VS_ESCAPE
 ---------------------------------------------------------------------------*/

int inCustGetBaseAmount(TRANSACTION_OBJECT* pobTran) {
    long lOpenAmount;
    int inResult,
    inTranCode; //, inAllow; cpac_2.2a
    char szDisplaySymbol[CUR_SYMBOL_SIZE + 1],
    szAmount[AMT_SIZE + 1];
    char szBuffer[21 + 1];
    inTranCode = pobTran->srBRec.inCode;
    lOpenAmount = 0L;

    vdGetMessageFromFile(EMPTY_STR_ERR_MSG, szBuffer);
    if (getgrid() == 0)
        vdDisplayAt(1, 4, szBuffer, CLR_EOL);//LENIN 2.2B
    else
        vdDisplayAt(1, inImamLineNumber, szBuffer, CLR_EOL);//LENIN 2.2B
    
	//vdCustDisplayPrompt(AMT_MSG, VS_TRUE); 

    BT_TRACE(' ', "Enter Base Amt");

    szAmount[0] = '\0';

    if (inTranCode == PRE_AUTH) {
        lOpenAmount = inGetOpenTabDAmt();
        lOpenAmount = lOpenAmount * 100;
        sprintf(szAmount, "%ld", lOpenAmount);
    }
    strcpy(szDisplaySymbol, szGetCurSymbol());
    sprintf(pobTran->srBRec.szIssueNumber, "%02d", inGetIssuerNumber() - 1);//LENIN

	if ((fGetImamAirlineTrx()) && (pobTran->srTRTRec.TransactionCode==SALE)) {  // for AIRLINE
		vdCustDisplayPrompt (FARE_MSG, VS_TRUE);
		if ((inResult = inCustGetAmount(szAmount, 1L, 999999999L, szDisplaySymbol, FARE_MSG)) != VS_SUCCESS)
			return(inResult);
	} else {
		vdCustDisplayPrompt (AMT_MSG, VS_TRUE); 
		if ((inResult = inCustGetAmount(szAmount, 1L, 999999999L, szDisplaySymbol, AMT_MSG)) != VS_SUCCESS)
			return(inResult);
	}

    pobTran->srBRec.lnBaseTransactionAmount = atol(szAmount);

    //LENIN 2.2     inAllow = inTotalTransAmtAlwd(pobTran);  //leo_apr27 added
    //LENIN 2.2 if (inAllow == VS_ERR) return (VS_ERR);


    //  inUpdate = inCPACTransAmtUpdate(pobTran);   //leo_apr27 added
    //  if (inUpdate == VS_ERR) return (VS_ERR);    //commented may2400 does not work when any txn fails!!!
    // negative test case!          
    return (VS_SUCCESS);
}


/*---------------------------------------------------------------------------
    Function     : inCustComputeAndDispTotal
    Description  : Custom fn for adds all the transaction amounts and displays it on
                   the screen.
    Returns      : VS_ERR, VS_SUCCESS or VS_ESCAPE
    Globals      : srGDS.szTotalTransactionAmount
    Modification History :
      #     Date      Who                     Description
    ----- -------- ----------   ---------------------------------------------
 ---------------------------------------------------------------------------*/

int inCustComputeAndDispTotal(TRANSACTION_OBJECT* pobTran) {
#ifndef IMAM_REMOVE
    char szAmount[AMT_SIZE + 1];
    int inGrid;
    int inLine;
    char szDate[DATE_SIZE + 1];
    char szTime[TIME_SIZE + 1];

    inGrid = getgrid();
    if (inGrid == 0)
        inLine = 4;
    else
        inLine = 7;

    vdComputeTransactionTotal(szAmount, pobTran);
    pobTran->srBKey.lnTotalOfTransactionAmount = atol(szAmount);

    if (fGetOffline(pobTran) && !pobTran->srBRec.fCloseTabSameCard)
        pobTran->srBRec.lnOrigTotalTransactionAmount = 0L;

    if (!fGetOffline(pobTran))
        pobTran->srBRec.lnOrigTotalTransactionAmount = atol(szAmount);

    /*    if (fComputeOverage(pobTran))
            pobTran->srBRec.fComputeOverage = VS_TRUE;
        else
            pobTran->srBRec.fComputeOverage = VS_FALSE;
    */ // 1.4 sad_change_1.4

    pobTran->srBRec.fComputeOverage = (fComputeOverage(pobTran));

    if ((fGetCheckFloorLimit(pobTran) == VS_TRUE) && (fAmountLessThanFloorLimit(pobTran) == VS_TRUE)) //leo_may102K added
    {
        //Bug Fix : The Floor Lt    
        inLoadTRTRec(pobTran, SALE_OFFLINE);                                                    // functionality was not working in Base!!
        vdSGCode(SALE_OFFLINE);       
        vdSetOffline(pobTran, VS_TRUE);
        pobTran->inTransactionCode = SALE_OFFLINE; //1.41 label G fix 
        pobTran->srBKey.fOffline = VS_TRUE;
        vdGetDate(szDate, MMDDYY); 
        strcpy(pobTran->srBRec.szDate, szDate);
        vdGetTime(szTime);
        strlcpy(pobTran->srBRec.szTime, szTime, DATE_SIZE);

        if (inCheckBannedCardType(pobTran) == VS_ERR)
            return(VS_ERR);

        inInitPrintOption(pobTran);
        vdMakeFooter(pobTran);
        pobTran->srBKey.fOffline = VS_TRUE;
        pobTran->srBRec.lnMessage = SALE_OFFLINE_MSG;
    }

    sprintf(szAmount, SUBSTITUTE_LD, pobTran->srBKey.lnTotalOfTransactionAmount);

    vdCustScroll(); // scroll 2 lines up
    vdDispMsgAt(TOTALAMT_MSG9, 1, inLine, CLR_EOL);
    vdFormatAmount(szAmount, VS_TRUE);    
    vdCustDispTotAmount(szAmount); 
    if ((inGetTipPercent() > 0) && (inGetTipProcessing() > TIP_OFF))
        vdDelay(PROMPT_DELAY);
    // to meet the spec... having all the amounts on the screen

    //vdCustScroll();  //: Do we need this?  
	// scroll 2 lines up as this may be followed by the  error 
    // or status messages which happens to be on the 7 th line 
    // as well

    /*
    if( fGetTRTOffline() )
       {
        int inPause;
           inPause = (int)(1.25*A_SECOND);
           ulTimerCount = set_itimeout( hClock, (unsigned)inPause, (long)TM_TICKS);
           while ( !KBHIT() && CHK_TIMEOUT(hClock, ulTimerCount) ) ;
       }
    */
#endif //IMAM_REMOVE
    return(VS_SUCCESS);
}



void vdCustDispTotAmount(char* pszAmount) {
    int inDispRow,
    inGrid;
    int inRowLim = inGetRowLim();
    int inDispCol; //, inDummyCol=1;

    inGrid = getgrid();
    if (inGrid == 0)
        inDispRow = 8;
    else
        inDispRow = inImamLineNumber-1;

    //vdScrollDataEntry(!obDisp.blNoScrollEntries); always scrolling
    //vdDispMsgAt(TOTALAMT_MSG9, obDisp.inHomeCol, inDispRow, CLR_EOL);
    if (obDisp.blActionFontASC8x21)
        vdDispStrAtRight(pszAmount, inDispRow, CLR_EOL);
    else {
        /*
           *        Display Amount Right Justified in English 8x21 font
           */
        inDispCol = (21 - strlen(pszAmount) + 1);
        //vdCalculateCoord (GRID_4x8_TO_8x21, &inDummyCol, &inDispRow);
        vdDisplayAt_ASC8X21(inDispCol, inDispRow, pszAmount, NO_CLEAR);
    }
}


/********************************************************************************************* 
* @func int | inCustGetTip | 
*       Modified version of inGetTip (base) which tests to 
*       assure that the tip amount does not exceed base amount.
*
* @parm TRANSACTION_OBJECT *| pobTran 
*       Transaction object
*
* @rdesc return values.
* @flag int | VS_SUCCESS or VS_ERR
* @end
**********************************************************************************************/

int inCustGetTip(TRANSACTION_OBJECT* pobTran) 
{
#ifdef ICICI
	szTempAmt[AMT_SIZE + 1];
#endif
	char szAmt[AMT_SIZE + 1], szDisplaySymbol[CUR_SYMBOL_SIZE + 1];
	int inRetVal,
	inAllow;
	int inSurcharge;
	long lnTempTip,
	lnTempBaseAmt;

	inSurcharge = 0;
	pobTran->srBRec.fTipEntered = VS_FALSE;
	memset(szAmt, 0, sizeof(szAmt));

	if (fGetImamAirlineTrx() && pobTran->srTRTRec.TransactionCode==SALE) {  //LIEM for AIRLINE
		pobTran->srBRec.fTipEntered = VS_TRUE;
        vdCustDisplayPrompt (NON_FARE_MSG, VS_TRUE); // scroll here
		strcpy (szDisplaySymbol,szGetCurSymbol());
		if ((inRetVal = inCustGetAmount(szAmt, 0L, pobTran->srBRec.lnBaseTransactionAmount, szDisplaySymbol, NON_FARE_MSG)) != VS_SUCCESS )
		{
			if (inRetVal == VS_ESCAPE) return(inRetVal);
			vdCustDisplayMessageFromFile( VALIDATE_ERR_MSG, WARNING_MSG);
			vdCustDisplayMessageFromFile( EMPTY_STR_ERR_MSG, STATUS_MSG);
			return(inRetVal);
		}		
		pobTran->srBRec.lnTipAmount = atol(szAmt);
		inAllow = inTotalTransAmtAlwd(pobTran); 
		if (inAllow == VS_ERR) return (VS_ERR);
		return (VS_SUCCESS);
	}

	if (pobTran->fTipAdjust) 
	{
		pobTran->srBRec.lnOldTotalTransactionAmount = pobTran->srBKey.lnTotalOfTransactionAmount;
		pobTran->srBRec.lnOldTipAmount = pobTran->srBRec.lnTipAmount;
	}

	if (inGetTipProcessing()==2) {  // to improve tip_adjust / tip prrompt and print behave
		pobTran->srBRec.lnTipAmount = 0L;
		pobTran->srBRec.fTipEntered = VS_TRUE;
	}

	#ifndef ICICI

		if ((inGetTipPercent() > 0) && (inGetTipProcessing() > TIP_OFF))
    		{
          		pobTran->srBRec.fTipEntered = VS_TRUE;
          		inRetVal = inComputePercent((long )inGetTipPercent(),szAmt, pobTran->srBRec.lnBaseTransactionAmount,TIP_FORMAT);
          		pobTran->srBRec.lnTipAmount = atol(szAmt);
		  	if (inRetVal != VS_SUCCESS) 
				return(inRetVal); 
    		}

	#endif  /* ICICI    */

	#ifdef ICICI
    	if ( (inGetTipProcessing() == TIP_ON_PROMPT) ||((inGGCode() == SALE && inGetTipProcessing() > TIP_OFF) 
			&& (pobTran->srBRec.inTranCardType == DEBIT_CARD ||pobTran->srBRec.inTranCardType == EBT_CARD)) )
    	{
			BT_TRACE(' ', "Enter Tip Amt");
			pobTran->srBRec.fTipEntered = VS_TRUE;
            		//vdCustDisplayPrompt (TIP_AMT_MSG, VS_TRUE); // scroll here
			while (VS_TRUE)
			{

				memset (szAmt,0,sizeof(szAmt));
				strcpy (szDisplaySymbol,szGetCurSymbol());
                          	inComputePercent((long )inGetTipPercent(),szTempAmt,pobTran->srBRec.lnBaseTransactionAmount,TIP_FORMAT);  
			    
                      	if(inGetTipPercent() <=0)                           
                            {
                           		/* if ( (inRetVal = inCustGetAmount(szAmt, 0L, pobTran->srBRec.lnBaseTransactionAmount, 
                           									szDisplaySymbol, TIP_AMT_MSG)) != VS_SUCCESS )
                                                       
					{
						if (inRetVal == VS_ESCAPE) return(inRetVal);
						vdCustDisplayMessageFromFile( VALIDATE_ERR_MSG, WARNING_MSG);
						vdCustDisplayMessageFromFile( EMPTY_STR_ERR_MSG, STATUS_MSG);
						return(inRetVal);
					}*/
					strcpy(szAmt,"000");
                         	}
            			lnTempTip = atol(szAmt);
            			lnTempBaseAmt = pobTran->srBRec.lnBaseTransactionAmount;

				#ifndef  CITI_PHIL
					if((lnTempTip >= lnTempBaseAmt) ||((inGGCode() == PRE_COMP) 
						&& ((lnTempTip + lnTempBaseAmt) > pobTran->srBRec.lnOldTotalTransactionAmount)))
				#endif/* CITI_PHIL */
				/*
					This is done as CitiBank Philippines wants to do Pre-Auth just as an Auth Only
					and Pre-comp just as an offline. There is a situation where Pre-Auth is done in
					one terminal and completion in another terminal, the old amount can never be
					used for verification... Vipin_27feb_Manila
				*/
				#ifndef CITI_PHIL
               			if(lnTempTip >= lnTempBaseAmt)
					{	// still give chance even if tip > = amount
						vdCustDisplayMessageFromFile( OUT_OF_RANGE_ERR_MSG, WARNING_MSG);
						vdCustDisplayMessageFromFile( EMPTY_STR_ERR_MSG, STATUS_MSG);
						vdCustDisplayPrompt (TIP_AMT_MSG, VS_FALSE); // Don't scroll here
						memset (szAmt,0,sizeof(szAmt));
						continue;
					}
				#endif /* CITI_PHIL Don_DSC_27feb_Citi_phil removed as no limit to Tip amt.*/
				//Kelvin_F2 --- start: add Excess Tip % checking
				#ifdef HKGM
			   		if (fExcessiveTip(pobTran,lnTempTip))
               			{
				   		vdCustDisplayMessageFromFile(TOO_MUCH_TIP_MSG, WARNING_MSG);
				   		vdCustDisplayPrompt (TIP_AMT_MSG, VS_FALSE);
				   		memset (szAmt,0,sizeof(szAmt));
				   		continue;
			   		}
				#endif /* HKGM */
				//Kelvin_F2 --- end: add Excess Tip % checking
				pobTran->srBRec.lnTipAmount = atol(szAmt);
			    	inAllow = inTotalTransAmtAlwd(pobTran);  //leo_apr27 added
				if (inAllow == VS_ERR) 
					return (VS_ERR);
				break;
			}
    	}

	#else
		if ((inGetTipProcessing() == TIP_ON_PROMPT) 
		||((inGGCode() == SALE && inGetTipProcessing() > TIP_OFF)  // : Disable this 2 line so debit card will not always ask for pin
		&& (pobTran->srBRec.inTranCardType == DEBIT_CARD ||pobTran->srBRec.inTranCardType == EBT_CARD)) 
		){
			BT_TRACE(' ', "Enter Tip Amt");
			pobTran->srBRec.fTipEntered = VS_TRUE;
            		vdCustDisplayPrompt (TIP_AMT_MSG, VS_TRUE); // scroll here
			while (VS_TRUE)
			{
        
				if (inGetTipPercent() == 0)  
					memset (szAmt,0,sizeof(szAmt));
				strcpy (szDisplaySymbol,szGetCurSymbol());
				#ifdef TIP_MAX_LIMIT_DEFINED 				
					if ( (inRetVal = inCustGetAmount(szAmt, 0L, pobTran->srBRec.lnBaseTransactionAmount,
                            										szDisplaySymbol, TIP_AMT_MSG)) != VS_SUCCESS )
				#else  
					if ( (inRetVal = inCustGetAmount(szAmt, 0L, 999999999L, szDisplaySymbol, TIP_AMT_MSG)) != VS_SUCCESS )
				#endif /* CITI_PHIL added citiphil_1.4_DON_DSC_28FEB NO LIMIT FOR TIP ADJUST */                            
				{
					if (inRetVal == VS_ESCAPE) return(inRetVal);
					vdCustDisplayMessageFromFile( VALIDATE_ERR_MSG, WARNING_MSG);
					vdCustDisplayMessageFromFile( EMPTY_STR_ERR_MSG, STATUS_MSG);
					return(inRetVal);
				}		
            			lnTempTip = atol(szAmt);
            			lnTempBaseAmt = pobTran->srBRec.lnBaseTransactionAmount;

				#ifndef  CITI_PHIL
					if((lnTempTip >= lnTempBaseAmt) ||((inGGCode() == PRE_COMP) 
						&& ((lnTempTip + lnTempBaseAmt) > pobTran->srBRec.lnOldTotalTransactionAmount)))
				#endif/* CITI_PHIL */
				/*
					This is done as CitiBank Philippines wants to do Pre-Auth just as an Auth Only
					and Pre-comp just as an offline. There is a situation where Pre-Auth is done in
					one terminal and completion in another terminal, the old amount can never be
					used for verification... Vipin_27feb_Manila
				*/
				#ifndef CITI_PHIL
               			if(lnTempTip >= lnTempBaseAmt)
					{	// still give chance even if tip > = amount
						vdCustDisplayMessageFromFile( OUT_OF_RANGE_ERR_MSG, WARNING_MSG);
						vdCustDisplayMessageFromFile( EMPTY_STR_ERR_MSG, STATUS_MSG);
						vdCustDisplayPrompt (TIP_AMT_MSG, VS_FALSE); // Don't scroll here
						memset (szAmt,0,sizeof(szAmt));
						continue;
					}
				#endif /* CITI_PHIL Don_DSC_27feb_Citi_phil removed as no limit to Tip amt.*/
				//Kelvin_F2 --- start: add Excess Tip % checking
				#ifdef HKGM
			   		if(fExcessiveTip(pobTran,lnTempTip))
               			{
				   		vdCustDisplayMessageFromFile(TOO_MUCH_TIP_MSG, WARNING_MSG);
				   		vdCustDisplayPrompt (TIP_AMT_MSG, VS_FALSE);
				   		memset (szAmt,0,sizeof(szAmt));
				   		continue;
			   		}
				#endif /* HKGM */
				//Kelvin_F2 --- end: add Excess Tip % checking
				pobTran->srBRec.lnTipAmount = atol(szAmt);
			    	inAllow = inTotalTransAmtAlwd(pobTran);  //leo_apr27 added
				if (inAllow == VS_ERR) 
					return (VS_ERR);

				break;
			}
	}
	#endif   /*ICICI */

	return(VS_SUCCESS);
} /* End of inNovaGetTip () */


void vdCustDisplayPrompt(long lnMsgId,VS_BOOL fScroll) {
    char szMessage[MESSAGE_SIZE + 1];
    int inGrid,
    inRow;

    vdGetMessageFromFile(lnMsgId, szMessage);
    if (fScroll)
        vdCustScroll();

    inGrid = getgrid();
    if (inGrid == 0)
        //#ifdef TLFB           //(Saritha_b1 moving out TLFB Switch )
        //inRow =3;
        //#else
        inRow = 4;
    //#endif 
    else
        inRow = inImamLineNumber-1;

    vdDisplayAt(1, inRow, szMessage, CLR_EOL);          // Amount:
}

void vdCustScroll(void) {
    int inGrid;

    inGrid = getgrid();

    if (inGrid == 0)    // 4 row mode
    {
        gotoxy(CUST_FIRST_COL_G2, CUST_SCROLL_START_ROW_G2);
        delline();
    } else {
        //gotoxy(CUST_FIRST_COL_G0, CUST_SCROLL_START_ROW_G0);
		gotoxy(CUST_FIRST_COL_G0, 2);  //LIEM
        delline();
        //delline();  no need to scroll 2 line
    }
}


void vdCustCalculateCoord(int inType,int* inCol,int* inRow) {
    int inX = *inCol,
    inY = *inRow;

    switch (inType) {
    case GRID_4x8_TO_8x21:
        // Assign 8x21 Column based in 4x8 Column
        *inCol = ((inX * 21) / 8);
        switch (inX) {
        case 1:
            *inCol = 1;
            break;
        case 2:
            *inCol = 4;
            break;
        case 3:
            *inCol = 8;
            break;
        case 4:
            *inCol = 12;
            break;
        case 5:
            *inCol = 15;
            break;
        case 6:
            *inCol = 17;
            break;
        case 7:
            *inCol = 19;
            break;
        case 8:
        default:
            *inCol = 21;
            break;
        }
        // Assign 8x21 Row based in 4x8 Row
        switch (inY) {
        case 1:
            *inRow = 1;
            break;
        case 2:
            *inRow = 3;
            break;
        case 3:
            *inRow = 5;
            break;
        case 4:
        default:
            *inRow = 7;
            break;
        }
        break;
    }
}



/*-------------------------------------------------------------------------
    Function    :   inCustGetAmount()
    Description :   get an amount from the user.  It also gets the currency
                    if asked for.
    Parameters  :   szAmount: string to store amount.
                    fAskforCurrency: 0: don't do currency ; 1: do currency.
  Returns     :     VS_SUCCESS: amount entered.
                    VS_ERROR:   CLEAR pressed.
    Modification History :
    #     Date      Who                     Description
  ----- -------- ---------- ---------------------------------------------
 -------------------------------------------------------------------------*/

int inCustGetAmount(char* szAmount,long lnMin,long lnMax,char* pszDisplaySymbol,long lnMsgId) {
    int x1,
    y1,
    x2,
    y2,
    inResult,
    inRowLim;

    char* szAmtFormat = szGetAmountFormat();
    char szCurSym[CUR_SYMBOL_SIZE + 1];
    int inDigitsInAmt = strlen(szAmtFormat);
    int inXPos;
    int inDigitCount,
    n,
    max;
    int inInputLine;
    int inMaxDigits;
    WIN_INFO wiCur8x21Win;
    int inGrid;
    char szTestAmt[12 + 1];

    szCurSym[0] = '\0';
    strcpy(szCurSym, pszDisplaySymbol);

    inGrid = getgrid();
    if (inGrid == 0)
        inInputLine = 4;
    else
        inInputLine = inImamLineNumber-1;

    for (inDigitCount = 0, n = 0, max = strlen(szAmtFormat); n < max; n++) {
        if (toupper(szAmtFormat[n]) == 'N')
            inDigitCount++;
    }

    inRowLim = inGetRowLim();   

    if (inGrid == 0) {
        vdCustCalculateCoord(GRID_4x8_TO_8x21, &inRowLim, &inInputLine);   // making it all 8x21

        //#ifdef TLFB           //(Saritha_b1  Moving out TLFB Switch)
        //inInputLine=6;
        //#else
        inInputLine = 8;  // overriding the input line to make it look better
        //#endif /* TLFB */
    }

    inXPos = inRowLim - inDigitsInAmt + 1;
    wherewin(&x1, &y1, &x2, &y2);

    /* Setup entry window */
    wiCur8x21Win.inLeft = inXPos;
    wiCur8x21Win.inTop = inInputLine;
    wiCur8x21Win.inRight = inRowLim;
    wiCur8x21Win.inBottom = inInputLine;

    inMaxDigits = inGetCPACMaxAmtEntryDigits();
    if (inMaxDigits > 10)
        inMaxDigits = 10;
    do {
        if (obDisp.blActionFontASC8x21)
            window(wiCur8x21Win.inLeft, wiCur8x21Win.inTop, wiCur8x21Win.inRight, wiCur8x21Win.inBottom);
        inResult = inEnterNumber(&wiCur8x21Win, szAmount, inMaxDigits, szCurSym, szAmtFormat);
        if (obDisp.blActionFontASC8x21)
            window(obDisp.inHomeCol, obDisp.inTitleLine, inRowLim, obDisp.inCharsPerColumn);
        if (inResult < 0)
            return(inResult);
        vdPurgeStrofChars(szAmount, ".,");

		LOG_PRINTFF((0x08L, "Entered Amount: [%s]", szAmount)); //LIEM
        memset(szTestAmt, 0x00, sizeof(szTestAmt));
        strcpy(szTestAmt, "2147483646");

        if (strcmp(szAmount, szTestAmt) > 0) {
            vdCustDisplayMessageFromFile(OUT_OF_RANGE_ERR_MSG, WARNING_MSG);
            vdCustDisplayMessageFromFile(EMPTY_STR_ERR_MSG, STATUS_MSG);
            vdCustDisplayPrompt(lnMsgId, VS_FALSE);
            memset(szAmount, 0, sizeof(szAmount));
            continue;
        }

        if ((str2long(szAmount) >= lnMin) && (str2long(szAmount) <= lnMax)) {
			LOG_PRINTFF((0x08L, "Amount %ld <= %ld <= %ld", lnMin, str2long(szAmount), lnMax)); //LIEM
            break;
		}
        vdCustDisplayMessageFromFile(OUT_OF_RANGE_ERR_MSG, WARNING_MSG);
        vdCustDisplayMessageFromFile(EMPTY_STR_ERR_MSG, STATUS_MSG);
        vdCustDisplayPrompt(lnMsgId, VS_FALSE);  // LENIN 2.2 
        memset(szAmount, 0, sizeof(szAmount));
    } while (1);

    window(x1, y1, x2, y2);
    return (VS_SUCCESS);
}


int inAdjCustGetAmount(char* szAmount,long lnMin,long lnMax,char* pszDisplaySymbol,long lnMsgId,TRANSACTION_OBJECT* pobTran) {
    int x1,
    y1,
    x2,
    y2,
    inResult,
    inRowLim;

    char* szAmtFormat = szGetAmountFormat();
    char szCurSym[CUR_SYMBOL_SIZE + 1];
    int inDigitsInAmt = strlen(szAmtFormat);
    int inXPos;
    int inDigitCount,
    n,
    max;
    int inInputLine;
    int inMaxDigits;
    WIN_INFO wiCur8x21Win;
    int inGrid;
    long lnAmt;
    char szTestAmt[12 + 1];
    //char szTipAmount[AMT_SIZE + 1];

    //sprintf(szTipAmount, SUBSTITUTE_LD, pobTran->srBRec.lnTipAmount);

    szCurSym[0] = '\0';
    strcpy(szCurSym, pszDisplaySymbol);

    inGrid = getgrid();
    if (inGrid == 0)
        //#ifdef TLFB           //(Saritha_b1 moving out TLFB Switch) 
        //inInputLine=3;
        //#else
        inInputLine = 4;
    //#endif 
    else
        inInputLine = 7;

    for (inDigitCount = 0, n = 0, max = strlen(szAmtFormat); n < max; n++) {
        if (toupper(szAmtFormat[n]) == 'N')
            inDigitCount++;
    }

    inRowLim = inGetRowLim();   

    if (inGrid == 0) {
        vdCustCalculateCoord(GRID_4x8_TO_8x21, &inRowLim, &inInputLine);   // making it all 8x21
        //#ifdef TLFB       //( Saritha_b1 moving out TLFB Switch)
        //inInputLine = 6;
        //#else 
        inInputLine = 8;  // overriding the input line to make it look better
        //#endif 
    }

    inXPos = inRowLim - inDigitsInAmt + 1;
    wherewin(&x1, &y1, &x2, &y2);

    /* Setup entry window */
    wiCur8x21Win.inLeft = inXPos;
    wiCur8x21Win.inTop = inInputLine;
    wiCur8x21Win.inRight = inRowLim;
    wiCur8x21Win.inBottom = inInputLine;

    inMaxDigits = inGetCPACMaxAmtEntryDigits();
    if (inMaxDigits > 10)
        inMaxDigits = 10;
    do {
        if (obDisp.blActionFontASC8x21)
            window(wiCur8x21Win.inLeft, wiCur8x21Win.inTop, wiCur8x21Win.inRight, wiCur8x21Win.inBottom);
        inResult = inEnterNumber(&wiCur8x21Win, szAmount, inMaxDigits, szCurSym, szAmtFormat);
        if (obDisp.blActionFontASC8x21)
            window(obDisp.inHomeCol, obDisp.inTitleLine, inRowLim, obDisp.inCharsPerColumn);
        if (inResult < 0)
            return(inResult);
        vdPurgeStrofChars(szAmount, ".,");

        memset(szTestAmt, 0x00, sizeof(szTestAmt));
        strcpy(szTestAmt, "2147483646");

        if (strcmp(szAmount, szTestAmt) > 0) {
            vdCustDisplayMessageFromFile(OUT_OF_RANGE_ERR_MSG, WARNING_MSG);
            vdCustDisplayMessageFromFile(EMPTY_STR_ERR_MSG, STATUS_MSG);
            vdCustDisplayPrompt(lnMsgId, VS_FALSE);
            memset(szAmount, 0, sizeof(szAmount));
            continue;
        }

        lnAmt = atol(szAmount);

        if (lnAmt < pobTran->srBRec.lnTipAmount) {
            vdCustDisplayMessageFromFile(OUT_OF_RANGE_ERR_MSG, WARNING_MSG);
            vdCustDisplayMessageFromFile(EMPTY_STR_ERR_MSG, STATUS_MSG);
            vdCustDisplayPrompt(lnMsgId, VS_FALSE);
            memset(szAmount, 0, sizeof(szAmount));
            continue;
        }

        if ((str2long(szAmount) >= lnMin) && (str2long(szAmount) <= lnMax))
            break;

        vdCustDisplayMessageFromFile(OUT_OF_RANGE_ERR_MSG, WARNING_MSG);
        vdCustDisplayMessageFromFile(EMPTY_STR_ERR_MSG, STATUS_MSG);
        vdCustDisplayPrompt(lnMsgId, VS_FALSE);  // LENIN 2.2 
        memset(szAmount, 0, sizeof(szAmount));
    } while (1);

    window(x1, y1, x2, y2);
    return (VS_SUCCESS);
}



void vdCustDisplayErrorString(char* szErrorString) {
    int inGrid;
    inGrid = getgrid();
    if (inGrid == 0)
        vdDisplayAt(1, 4, szErrorString, CLR_EOL);
    else
        vdDisplayAt(1, inImamLineNumber, szErrorString, CLR_EOL);
    vdBeep();
    vdFlushKeyboardBuffer();
    inWaitKey(inGetIdleTimeOut());
}

void vdCustDisplayWarningString(char* szString) {
    int inRow; 
    int inRowLim = inGetRowLim();
    int inGrid;
    inGrid = getgrid();
    if (inGrid == 0)
        inRow = 4;
    else
        inRow = inImamLineNumber;
    vdDisplayAt(1, inRow, szString, CLR_EOL);
    vdWarnBeep();
    vdDelay(ERR_MSG_DELAY);
}

void vdCustDisplayStatusString(char* szString) {
    int inGrid,
    inRow;

    inGrid = getgrid();
    if (inGrid == 0)
        inRow = 4;
    else
        inRow = inImamLineNumber;

    vdDisplayAt(1, inRow, szString, CLR_EOL);
}

void vdCustDisplayMessageFromFile(long lnMessageIndex,int inMsgType) {
    char szMessage[MESSAGE_SIZE + 1];
    vdGetMessageFromFile(lnMessageIndex, szMessage);
    switch (inMsgType) {
    case STATUS_MSG:
        vdCustDisplayStatusString(szMessage);
        break;
    case ERROR_MSG:
        vdCustDisplayErrorString(szMessage);
        break;
    case WARNING_MSG:
    default:
        vdCustDisplayWarningString(szMessage);
        break;
    }
}

#undef VSOPER_C





